﻿using System.Data;
using NUnit.Framework;

namespace Azalea.Test.ORMap
{
    [TestFixture]
    public class DBContextTester : Config
    {
        [Test]
        public void GetSchemaTest()
        {
            DataSet schema = _dbContext.GetDbSchema();
            schema.WriteXmlSchema(@"c:\schema.xml");

            string tableName = schema.Tables[0].TableName;
            DataTable table = _dbContext.GetTableSchema(tableName);
            Assert.AreEqual(table.TableName, tableName);
        }

        [Test]
        public void OpenCloseConnectionTest()
        {
            IDbConnection connection = _dbContext.OpenConnection(true);
            Assert.AreEqual(ConnectionState.Open, connection.State);

            _dbContext.CloseConnection(connection);
            Assert.AreEqual(ConnectionState.Closed, connection.State);

            connection = _dbContext.OpenConnection(false);
            Assert.AreEqual(ConnectionState.Closed, connection.State);

            _dbContext.CloseConnection(connection);
            Assert.AreEqual(ConnectionState.Closed, connection.State);
        }
    }
}